package textdiff {
	
	/**
	 * One of the two files being compared. lineNum supports nextBlock something like
	 * an iterator.
	 */
	public class FileInfo {
	    public var lines: Array;
	    public var lineInfo: Array;
	    public var length: int;
	    public var lineNum: int;
	    private static const EOF:LineInfo = new LineInfo( -1, -1, -1, -1 );
	
	    public function FileInfo(lines: Array) {
	        this.lines = lines;
	        length = lines.length;
	        lineInfo = new Array();
	    }
	
	    public function currentLineInfo(): LineInfo {
	        return lineInfoAt( lineNum );
	    }
	
	    public function lineInfoAt( lineNum:int): LineInfo {
	        if (lineNum >= lines.length)
	            return EOF;
	        else
	            return lineInfo[lineNum];
	    }
	
	    public function nextBlock(): LineBlock {
	        var lineBlock:LineBlock = getBlockAt( lineNum );
	        if (null != lineBlock)
	            lineNum += lineBlock.lines.length; 
	        return lineBlock;
	    }
	
	    public function getBlockAt(lineNum:int): LineBlock {
	        if (lineNum >= lines.length)
	            return null;
	        var fromLineNum:int = lineNum;
	        var blockNum:int = lineInfo[lineNum].blockNum;
	        while (blockNum == lineInfoAt( lineNum ).blockNum)
	        {
	            lineNum++;
	        }
	        var thruLineNum:int = lineNum - 1;
	        var lBlock:LineBlock = new LineBlock( lines, fromLineNum, thruLineNum );
	        return lBlock;
	    }
	
	    public function setBlockNumber(lineNum:int, blockNum:int): void {
	        lineInfo[lineNum].setBlockNumber( blockNum );
	    }
	
	    public function isValidLineNum(lineNum:int): Boolean {
	        return ((lineNum >= 0) && (lineNum < lines.length));
	    }
	}
}